Skip to content

fix(precompile): skip precompilation for directory and pyc inputs in srcs - #4113

Merged
rickeylev merged 14 commits into
bazel-contrib:mainfrom
rickeylev:skip_precompile_src_errors
Aug 26, 2026
Merged

fix(precompile): skip precompilation for directory and pyc inputs in srcs#4113
rickeylev merged 14 commits into
bazel-contrib:mainfrom
rickeylev:skip_precompile_src_errors

Conversation

@rickeylev

Copy link
Copy Markdown
Collaborator

Precompiling py_library, py_binary, or py_test targets fails when
srcs contains directory artifacts or .pyc files. The precompiler
declares invalid actions on directories and drops non-.py sources from
default outputs.

This change:

  • Expands direct sources to include Python files, .pyc files, and
    directories.
  • Skips precompilation for directories and non-Python files while
    retaining them in default outputs.
  • Updates srcs validation and documentation.

Add analysis and execution tests verifying precompiling behavior when directory or pyc file inputs are passed in target srcs.
Directories and precompiled pyc files cannot be compiled directly into pyc files. Skip precompiling when src.is_directory is true or the extension is pyc/pyo while retaining them in target outputs.
… srcs

Allow arbitrary files in the srcs attribute while filtering to Python source files via an is_py_source helper. Skip precompilation for directories or any file that is not a Python source file, and remove legacy py3 extension references.
…mat srcs doc

Propagate input .pyc files through precompilation into target default outputs, and format the srcs attribute docstring with a list of allowed file types.
…ies to maybe_precompile

Compute direct_sources as the py, pyc, and directory files from srcs, pass direct_sources to maybe_precompile, and update tree artifact analysis test outputs.
…ecompile doc

Factor out filter_to_direct_sources helper in common.bzl to share direct sources filtering across py_library and py_executable, and update _precompile return type docstring.
…bzl_library dep

Add news fragment for skip precompile src errors fix, document allowed srcs file types with versionchanged in attributes.bzl, and add :common dependency to precompile bzl_library.
Associate news entry with newly created PR bazel-contrib#4113.
…ctive

Update version directive in attributes.bzl from VERSION_NEXT_FEATURE to VERSION_NEXT_PATCH.
…ntry

Update news/4113.fixed.md to use valid Sphinx MyST {obj} syntax, wrap lines within 80 columns, and link to PR bazel-contrib#4113.
@rickeylev
rickeylev marked this pull request as ready for review August 25, 2026 07:43
@rickeylev
rickeylev requested a review from aignas as a code owner August 25, 2026 07:43
Comment thread python/private/py_library.bzl Outdated
Comment thread python/private/py_library.bzl Outdated

@aignas aignas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending the comments, LGTM.

…te doc

Remove redundant srcs_attr.set_allow_files(True) from py_library_impl_builder
and consolidate the 2.3.2 versionchanged doc into COMMON_ATTRS srcs in attributes.bzl.
@rickeylev
rickeylev enabled auto-merge August 26, 2026 07:43
@rickeylev
rickeylev added this pull request to the merge queue Aug 26, 2026
Merged via the queue into bazel-contrib:main with commit c953e5e Aug 26, 2026
5 checks passed
@rickeylev
rickeylev deleted the skip_precompile_src_errors branch August 26, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants